﻿using Infra.CustomException.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infra.CustomException
{
    public class UtilException : BaseException, IExceptionForShow
    {
        public UtilException(Exception exception)
            : base(exception)
        {
            if (Logger == null)
            {
                var errorMessage = new StringBuilder();
                errorMessage.Append("******************************************************************* Utils Error ***********************************************************");
                errorMessage.Append(exception.Message);
                errorMessage.Append("******************************************************************* Utils Error ***********************************************************");

                Logger.Error("Util Exception", exception);
                Logger.Error(errorMessage.ToString());
            }
        }

        public UtilException(string message)
            : base(message)
        { }

        public string MessageKey
        {
            get
            {
                return base._message;
            }
        }

        public string GetMessage(CultureInfo culture)
        {
            var result = "";

            if (base._message == null || base._message.Equals(""))
            {
                if (base.InnerException is NullReferenceException)
                    result = UtilResource.ResourceManager.GetString(UtilResource.null_pointer, culture);
            }
            else
                result = UtilResource.ResourceManager.GetString(base._message, culture);

            return result;
        }
    }
}
